package com.freshcity.page.welcome
{
	import com.freshcity.component.container.Component;
	import com.freshcity.component.container.HBox;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.core.OpCodes;
	import com.freshcity.lib.event.DataEvent;
	import com.freshcity.lib.event.EventName;
	import com.freshcity.manager.EffectManager;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.welcome.RegisterWin;
	import com.greensock.TweenMax;
	import com.greensock.loading.LoaderMax;
	
	import fl.controls.ComboBox;
	import fl.controls.RadioButtonGroup;
	import fl.data.DataProvider;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class Register extends Component
	{
		private var back:RegisterWin;
		private var propertyItem2:ComboBox;
		private var propertyItem1:ComboBox;
		private var provinceBox:ComboBox;

		private var xml:XML=LoaderMax.getContent("dataXML");

		public function Register(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			super(LayerManager.popupLayer, xpos, ypos);
			this.x=(stage.stageWidth - back.width) / 2;
			this.y=(stage.stageHeight - back.height) / 2;

			back.submitBtn.addEventListener(MouseEvent.CLICK, onSubmitClickHandler);
		}

		protected function onSubmitClickHandler(event:MouseEvent):void
		{
			var value1:String;

			if (propertyItem1.selectedIndex > 0)
			{
				value1=provinceBox.selectedLabel + '-' +propertyItem1.selectedLabel;
			}
			else
			{
				main.msg.showRollTipsMsg("请提供居住地信息");
				return;
			}

			if (back.birthYear.selectedIndex <= 0)
			{
				main.msg.showRollTipsMsg("请提供出生年份");
				return;
			}

			if (back.tall.selectedIndex <= 0)
			{
				main.msg.showRollTipsMsg("请提供身高信息");
				return;
			}
			if (back.degree.selectedIndex <= 0)
			{
				main.msg.showRollTipsMsg("请提供学历信息");
				return;
			}
			if (back.marriage.selectedIndex <= 0)
			{
				main.msg.showRollTipsMsg("请提供婚姻状况信息");
				return;
			}

			var data:*={};
			data.level="0";
			data.data1=value1;
			data.data2=back.birthYear.selectedLabel;
			data.data4=back.tall.selectedLabel;
			data.data5=back.degree.selectedLabel;
			data.data6=back.marriage.selectedLabel;

			var intro:SelfIntro=new SelfIntro();
			intro.data=data;
			intro.main=main;
			intro.show();
			this.destroy();
			//main.commu.send(OpCodes.UPGRADE_LEVEL, data);
		}

		override protected function addChildren():void
		{
			super.addChildren();
			back=new RegisterWin();
			back.mouseEnabled=false;
			addChild(back);

			var item1:HBox=new HBox();
			provinceBox=new ComboBox();
			var da:Array=[];
			da.push({label: '请选择'});
			for each (var x:XML in xml.cities.prov)
			{
				da.push({label: x.@label});
			}
			provinceBox.dataProvider=new DataProvider(da);
			provinceBox.addEventListener(Event.CHANGE, provinceSelected);

			//居住地
			propertyItem1=new ComboBox();
			propertyItem1.name="address";
			item1.addChild(provinceBox);
			item1.addChild(propertyItem1);
			item1.initialize();
			item1.x=150;
			item1.y=104.25;
			back.addChild(item1);

			//出生年份
			var dateArray:Array=[];
			dateArray.push({label: '请选择'});
			for each (x in xml.year.children())
			{
				dateArray.push({label: x.@value});
			}
			back.birthYear.dataProvider=new DataProvider(dateArray);
			back.birthYear.selectedIndex=0;

			//身高
			var tallArray:Array=[];
			tallArray.push({label: '请选择'});
			for each (x in xml.tall.children())
			{
				tallArray.push({label: x.@value});
			}
			back.tall.dataProvider=new DataProvider(tallArray);
			back.tall.selectedIndex=28;

			//学历
			var degreeArray:Array=[];
			degreeArray.push({label: '请选择'});
			for each (x in xml.degree.children())
			{
				degreeArray.push({label: x.@value});
			}
			back.degree.dataProvider=new DataProvider(degreeArray);
			back.degree.selectedIndex=0;

			//婚姻状况
			var marriageArray:Array=[];
			marriageArray.push({label: '请选择'});
			for each (x in xml.marriage.children())
			{
				marriageArray.push({label: x.@value});
			}
			back.marriage.dataProvider=new DataProvider(marriageArray);
			back.marriage.selectedIndex=0;
		}

		private function provinceSelected(e:Event):void
		{
			var da:Array=[];
			var c:ComboBox=e.currentTarget as ComboBox;
			da.push({label: '请选择'});
			for each (var x:XML in xml.cities.prov.(@label == c.selectedItem.label).children())
			{
				da.push({label: x.@value});
			}
			propertyItem1.dataProvider=new DataProvider(da);
		}

		override public function destroy():void
		{
			back.submitBtn.removeEventListener(MouseEvent.CLICK, onSubmitClickHandler);
			super.destroy();
		}

		override public function show(event:Event=null):void
		{
			EffectManager.addUIMask([],0);
			super.show(event);
		}

		override public function hide(event:Event=null):void
		{
			EffectManager.hideUIMask();
			super.hide();
		}
	}
}
